import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "@/views/Home";
import NewsList from "@/views/NewsList";
import GoodsList from "@/views/GoodsList";
import MyHeader from "@/views/MyHeader";
import MyMain from "@/views/MyMain";
import MyFooter from "@/views/MyFooter";
import My from "@/views/My";
import NotFound from "@/views/NotFound";

Vue.use(VueRouter)

const routes = [
  {
    path: "/",// 指定路由地址
    name: "index",
    component: Home// 当请求地址与路由地址匹配时，那么会使用组件Home
  },
  {
    // 支持的请求地址除/newsList以及，还支持/news
    path: "/newsList",
    name: "newsList",
    alias: "/news",// 为地址起别名
    component: NewsList
  },
  {
    path: "/goodsList",
    name: "goodsList",
    // 可以设置为数组，起多个别名
    alias: ["/first", "/daoLang", "/wangFei"],
    component: GoodsList
  },
  {
    path: "/my",
    name: "my",
    // 单页面多路由(了解）
    components: {
      one: MyHeader,
      main: MyMain,
      footer: MyFooter,
      default: My
    }
  },
  {
    path: "*",
    component: NotFound
  },
  {
    // redirect:重定向--》当请求地址为/home,被重定向至地址/
    path: "/home",
    redirect: "/"
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
